import {
    GET_RECOMMEND,
    GET_DETAIL,
    ADD_BOOK,
    DELE_BOOK
} from './actionType'
const data = {
    recommend: [],
    detail: [],
    book: []
}


export default function (state = data, action) {
    switch (action.type) {
        case GET_RECOMMEND:
            const recommendState = JSON.parse(JSON.stringify(state));
            recommendState.recommend = action.payload
            // console.log(recommendState);
            return recommendState
        case GET_DETAIL:
            const detailState = JSON.parse(JSON.stringify(state));
            detailState.detail = action.payload
            return detailState
        case ADD_BOOK:
            const bookState = JSON.parse(JSON.stringify(state));
            bookState.book.push(action.payload) 
            // console.log(bookState);
            return bookState
        case DELE_BOOK:
            const delebookState = JSON.parse(JSON.stringify(state));
            delebookState.book.splice(action.payload) 
            // console.log(delebookState);
            return delebookState

        default:
            return state
    }

}